import $ from '../common';
Page({
  data: {
    titleHeight: $.gData().titleHeight,
    statuHeight: $.gData().statuHeight,
    form: {},
    // profile: '', //名称
    // age: '', //年龄
    // teaage: '', //教龄
    // idcard: '', //身份证
    // sex: '', //性别
    teacherinfo: {}
  },
  //选择性别
  chooseSex() {
    let arr = ['男', '女']
    $.actionSheet(arr, (index) => {
      if (index == 0) {
        this.setData({
          gender: 'male'
        })
      } else {
        this.setData({
          gender: 'female'
        })
      }
      this.alterinfo()
    })
  },
  //更换图像
  changeavatar(e) {
    let {
      field
    } = e.currentTarget.dataset
    wx.chooseImage({
      count: 1,
      success: (res) => {
        console.log(res);
        $.upload("/image/upload/oss", {
          filePaths: res.tempFilePaths
        }, ras => {
          let info = {
            teacher_uuid: wx.getStorageSync('teacher_uuid'),
            campus_uuid: wx.getStorageSync('campus_uuid')
          }
          info[field] = ras[0]
          $.post("/teacher/update", info, res => {
            this.getuserinfo()
          })
        })
      }
    })
  },
  // 去往修改名字
  altername() {
    $.navigateTo(`/my/setupinfo?title=设置姓名&field=name&type=1&ner=${this.data.teacherinfo.name}`)
  },
  //去往修改年龄
  alterage() {
    $.navigateTo(`/my/setupinfo?title=设置年龄&field=age&type=2&ner=${this.data.teacherinfo.age}`)
  },
  //往修改教龄
  alterteaage() {
    $.navigateTo(`/my/setupinfo?title=设置教龄&field=teache_age&type=2&ner=${this.data.teacherinfo.teache_age}`)
  },
  // 去往修改身份证
  alteridcard() {
    $.navigateTo(`/my/setupinfo?title=设置身份证&field=idcard_no&type=1&ner=${this.data.teacherinfo.idcard_no}`)
  },
  // 去往修改密码
  goamendpassword() {
    $.navigateTo(`/my/amend?phone=${this.data.teacherinfo.phone}`)
  },
  //获取用户账号
  getuserinfo() {
    $.get("/teacher/detail", {}, (res) => {
      this.setData({
        teacherinfo: res.teacher
      })
    })
  },
  //修改性别
  alterinfo() {
    let data = {
      teacher_uuid: wx.getStorageSync('teacher_uuid'),
      campus_uuid: wx.getStorageSync('campus_uuid'),
    }
    data.gender = this.data.gender
    $.post("/teacher/update", data, (res) => {
      this.getuserinfo()
    })
  },
  onLoad(e) {},
  onShow() {
    this.getuserinfo()
  },
})